using UnityEngine;

public class InputMgr : Singleton<InputMgr>
{
    //是否检测输入
    private bool m_bCheckInput = false;
    public InputMgr()
    {
        MonoMgr.GetInstance().AddUpdateListener(Update);
    }

    /// <summary>
    /// 开启检测
    /// </summary>
    public void Open()
    {
        m_bCheckInput = true;
    }
    
    /// <summary>
    /// 关闭检测
    /// </summary>
    public void Close()
    {
        m_bCheckInput = false;
    }

    /// <summary>
    /// 检测输入
    /// </summary>
    /// <param name="key"></param>
    public void CheckKeyCode(KeyCode key)
    {
        if (Input.GetKeyDown(key))
            ListenerMgr.GetInstance().Trigger("onKeyDown", key);
        if (Input.GetKeyUp(key))
            ListenerMgr.GetInstance().Trigger("onKeyUp", key);

    }

    private void Update()
    {
        if (!m_bCheckInput)
            return;
        CheckKeyCode(KeyCode.W);
        CheckKeyCode(KeyCode.S);
        CheckKeyCode(KeyCode.A);
        CheckKeyCode(KeyCode.D);
    }
}
